]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
tests/shell: Add basic multi-monitor test
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Fri, 31 Oct 2025 03:37:49 +0000 (04:37 +0100)
committerMarge Bot <marge-bot@gnome.org>
Mon, 3 Nov 2025 12:14:29 +0000 (12:14 +0000)
We only care about creating a new monitor and ensure that the new
geometries respect the monitors setup

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3943>

tests/meson.build
tests/shell/multiMonitor.js [new file with mode: 0644]

index f51d1e8c24f09c4cdb89f38298e06365a5b4be26..373bf90e976aab30279ad2bc5021405ed3169ab5 100644 (file)
@@ -85,6 +85,9 @@ shell_tests = [
   {
     'name': 'closeWithActiveWindows',
   },
+  {
+    'name': 'multiMonitor',
+  },
   {
     'name': 'headlessStart',
     'options': ['--hotplug'],
diff --git a/tests/shell/multiMonitor.js b/tests/shell/multiMonitor.js
new file mode 100644 (file)
index 0000000..d69890a
--- /dev/null
@@ -0,0 +1,64 @@
+import MetaTest from 'gi://MetaTest';
+
+import * as Main from 'resource:///org/gnome/shell/ui/main.js';
+
+/**
+ * init:
+ */
+export function init() {}
+
+/**
+ * run:
+ */
+export async function run() {
+    const monitorsChangedPromise = new Promise(resolve => {
+        const monitorsChangedHandlerId = Main.layoutManager.connect('monitors-changed',
+            () => {
+                Main.layoutManager.disconnect(monitorsChangedHandlerId);
+                resolve();
+            });
+    });
+
+    MetaTest.TestMonitor.new(global.context, 1280, 720, 60.0);
+    await monitorsChangedPromise;
+}
+
+function expectEqual(a, b, desc = null) {
+    if (a !== b)
+        throw new Error(`${desc ? `${desc} ` : ''}${a} does not match ${b}`);
+}
+
+/**
+ * finish:
+ */
+export function finish() {
+    const monitors = [];
+
+    expectEqual(global.display.get_n_monitors(), 2, 'Configured monitors');
+
+    for (let i = 0; i < global.display.get_n_monitors(); ++i)
+        monitors.push(global.display.get_monitor_geometry(i));
+
+    const expectedScreenWidth = monitors.reduce((sum, m) => sum + m.width, 0);
+    const expectedScreenHeight = monitors.reduce((max, m) => Math.max(max, m.height), 0);
+    console.log(`Expecting screen to have size of: ${expectedScreenWidth}x${expectedScreenHeight}`);
+
+    expectEqual(global.screen_width, expectedScreenWidth, 'Screen Width');
+    expectEqual(global.screen_height, expectedScreenHeight, 'Screen Height');
+
+    expectEqual(global.stage.width, global.screen_width, 'Stage Width');
+    expectEqual(global.stage.height, global.screen_height, 'Stage Height');
+
+    expectEqual(Main.layoutManager.monitors.length, monitors.length, 'Monitors length');
+    expectEqual(Main.layoutManager.primaryMonitor, Main.layoutManager.monitors[0], 'Primary Monitor');
+    expectEqual(Main.layoutManager._bgManagers.length, monitors.length, 'Background Managers length');
+
+    for (let i = 0; i < monitors.length; ++i) {
+        const monitor = Main.layoutManager.monitors[i];
+        expectEqual(monitor.index, i, `Monitor ${i} index`);
+        expectEqual(monitor.x, monitors[i].x, `Monitor ${i} x`);
+        expectEqual(monitor.y, monitors[i].y, `Monitor ${i} y`);
+        expectEqual(monitor.width, monitors[i].width, `Monitor ${i} width`);
+        expectEqual(monitor.height, monitors[i].height, `Monitor ${i} height`);
+    }
+}